﻿using System.Collections.Generic;
using System.Data;
using System.IO;

namespace Smart
{
    public class Entity
    {
        private static Entity _entity;
        private Entity() { }
        public static Entity Get
        {
            get
            {
                if (_entity == null)
                    _entity = new Entity();
                return _entity;
            }
        }

        Dictionary<string, TableObject> tables = new Dictionary<string, TableObject>();
        public Dictionary<string, TableObject> Tables { get { return tables; } }

        public void Init()
        {
            TableObject stok = new TableObject();
            stok.TableName = "TBL_STOK";
            stok.Fields.Add("recId", new FieldObject() { dbAdi = "rec_id", dbType = DbType.Int32, idx = 0 });
            stok.Fields.Add("Kod", new FieldObject() { dbAdi = "stk_kod", dbType = DbType.String, idx = 1 });
            stok.Fields.Add("Adi", new FieldObject() { dbAdi = "stk_adi", dbType = DbType.String, idx = 2 });
            stok.Fields.Add("dovizCinsi", new FieldObject() { dbAdi = "stk_dvz", dbType = DbType.Byte, idx = 3 });
            stok.Fields.Add("birim1Adi", new FieldObject() { dbAdi = "stk_birim1adi", dbType = DbType.String, idx = 4 });
            stok.Fields.Add("birim1Katsayi", new FieldObject() { dbAdi = "stk_birim1katsayi", dbType = DbType.Decimal, idx = 5 });
            stok.Fields.Add("birim2Adi", new FieldObject() { dbAdi = "stk_birim2adi", dbType = DbType.String, idx = 6 });
            stok.Fields.Add("birim2Katsayi", new FieldObject() { dbAdi = "stk_birim2katsayi", dbType = DbType.Decimal, idx = 7 });
            stok.Fields.Add("birim3Adi", new FieldObject() { dbAdi = "stk_birim3adi", dbType = DbType.String, idx = 8 });
            stok.Fields.Add("birim3Katsayi", new FieldObject() { dbAdi = "stk_birim3katsayi", dbType = DbType.Decimal, idx = 9 });
            stok.Fields.Add("birim4Adi", new FieldObject() { dbAdi = "stk_birim4adi", dbType = DbType.String, idx = 10 });
            stok.Fields.Add("birim4Katsayi", new FieldObject() { dbAdi = "stk_birim4katsayi", dbType = DbType.Decimal, idx = 11 });
            stok.Fields.Add("fiyat1", new FieldObject() { dbAdi = "stk_fiyat1", dbType = DbType.Decimal, idx = 12 });
            stok.Fields.Add("fiyat2", new FieldObject() { dbAdi = "stk_fiyat2", dbType = DbType.Decimal, idx = 13 });
            stok.Fields.Add("fiyat3", new FieldObject() { dbAdi = "stk_fiyat3", dbType = DbType.Decimal, idx = 14 });
            stok.Fields.Add("fiyat4", new FieldObject() { dbAdi = "stk_fiyat4", dbType = DbType.Decimal, idx = 15 });
            stok.Fields.Add("fiyat5", new FieldObject() { dbAdi = "stk_fiyat5", dbType = DbType.Decimal, idx = 16 });
            stok.Fields.Add("fiyat1Iskonto", new FieldObject() { dbAdi = "stk_iskonto1_kod", dbType = DbType.String, idx = 17 });
            stok.Fields.Add("fiyat2Iskonto", new FieldObject() { dbAdi = "stk_iskonto2_kod", dbType = DbType.String, idx = 18 });
            stok.Fields.Add("fiyat3Iskonto", new FieldObject() { dbAdi = "stk_iskonto3_kod", dbType = DbType.String, idx = 19 });
            stok.Fields.Add("fiyat4Iskonto", new FieldObject() { dbAdi = "stk_iskonto4_kod", dbType = DbType.String, idx = 20 });
            stok.Fields.Add("fiyat5Iskonto", new FieldObject() { dbAdi = "stk_iskonto5_kod", dbType = DbType.String, idx = 21 });
            stok.Fields.Add("VergiSira", new FieldObject() { dbAdi = "stk_vergi_no", dbType = DbType.Byte, idx = 22 });
            stok.Fields.Add("VergiOran", new FieldObject() { dbAdi = "stk_vergi_oran", dbType = DbType.Decimal, idx = 23 });

            stok.Indexes.Add("PK", new IndexObject() { Fields = "rec_id", IndexType = IndexObject.Tip.PrimaryKey });
            stok.Indexes.Add("KODU", new IndexObject() { Fields = "stk_kod", IndexType = IndexObject.Tip.Index });
            stok.Indexes.Add("ISIM", new IndexObject() { Fields = "stk_adi", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_STOK", stok);

            TableObject barkod = new TableObject();
            barkod.TableName = "TBL_BARKOD";
            barkod.Fields.Add("recId", new FieldObject() { dbAdi = "rec_id", dbType = DbType.Int32, idx = 0 });
            barkod.Fields.Add("StokId", new FieldObject() { dbAdi = "bk_stok_id", dbType = DbType.Int32, idx = 1 });
            barkod.Fields.Add("StokKodu", new FieldObject() { dbAdi = "bk_stok_kodu", dbType = DbType.String, idx = 2 });
            barkod.Fields.Add("Barkodu", new FieldObject() { dbAdi = "bk_barkod", dbType = DbType.String, idx = 3 });
            barkod.Fields.Add("Icerik", new FieldObject() { dbAdi = "bk_icerik", dbType = DbType.Byte, idx = 4 });
            barkod.Fields.Add("Tip", new FieldObject() { dbAdi = "bk_tip", dbType = DbType.Byte, idx = 5 });
            barkod.Fields.Add("BirimNo", new FieldObject() { dbAdi = "bk_birimno", dbType = DbType.Byte, idx = 6 });
            barkod.Indexes.Add("PK", new IndexObject() { Fields = "bk_barkod", IndexType = IndexObject.Tip.PrimaryKey });
            barkod.Indexes.Add("STOKID", new IndexObject() { Fields = "bk_stok_id", IndexType = IndexObject.Tip.Index });
            barkod.Indexes.Add("ID", new IndexObject() { Fields = "rec_id", IndexType = IndexObject.Tip.Index });
            barkod.Indexes.Add("STOKKOD", new IndexObject() { Fields = "bk_stok_kodu", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_BARKOD", barkod);

            TableObject depo = new TableObject();
            depo.TableName = "TBL_DEPO";
            depo.Fields.Add("recId", new FieldObject() { dbAdi = "rec_id", dbType = DbType.Int32, idx = 0 });
            depo.Fields.Add("Kodu", new FieldObject() { dbAdi = "dep_kodu", dbType = DbType.String, idx = 1 });
            depo.Fields.Add("Adi", new FieldObject() { dbAdi = "depo_adi", dbType = DbType.String, idx = 2 });
            depo.Indexes.Add("PK", new IndexObject() { Fields = "rec_id", IndexType = IndexObject.Tip.PrimaryKey });
            depo.Indexes.Add("KOD", new IndexObject() { Fields = "dep_kodu", IndexType = IndexObject.Tip.Index });
            depo.Indexes.Add("AD", new IndexObject() { Fields = "depo_adi", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_DEPO", depo);


            TableObject srm = new TableObject();
            srm.TableName = "TBL_SRM";
            srm.Fields.Add("recId", new FieldObject() { dbAdi = "rec_id", dbType = DbType.Int32, idx = 0 });
            srm.Fields.Add("Kodu", new FieldObject() { dbAdi = "srm_kodu", dbType = DbType.String, idx = 1 });
            srm.Fields.Add("Adi", new FieldObject() { dbAdi = "srm_adi", dbType = DbType.String, idx = 2 });
            srm.Indexes.Add("PK", new IndexObject() { Fields = "rec_id", IndexType = IndexObject.Tip.PrimaryKey });
            srm.Indexes.Add("KOD", new IndexObject() { Fields = "srm_kodu", IndexType = IndexObject.Tip.Index });
            srm.Indexes.Add("AD", new IndexObject() { Fields = "srm_adi", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_SRM", srm);


            TableObject depoMiktar = new TableObject();
            depoMiktar.TableName = "TBL_ENVANTER";
            depoMiktar.Fields.Add("recId", new FieldObject() { dbAdi = "rec_id", dbType = DbType.Int32, idx = 0 });
            depoMiktar.Fields.Add("DepoId", new FieldObject() { dbAdi = "depo_id", dbType = DbType.Int32, idx = 1 });
            depoMiktar.Fields.Add("Miktar", new FieldObject() { dbAdi = "env_miktar", dbType = DbType.Decimal, idx = 2 });
            depoMiktar.Indexes.Add("PK", new IndexObject() { Fields = "rec_id,depo_id", IndexType = IndexObject.Tip.PrimaryKey });
            this.tables.Add("TBL_ENVANTER", depoMiktar);

            TableObject sayim = new TableObject();
            sayim.TableName = "TBL_SAYIM";
            sayim.Fields.Add("Tarih", new FieldObject() { dbAdi = "sym_tarih", dbType = DbType.DateTime, idx = 0 });
            sayim.Fields.Add("DepoNo", new FieldObject() { dbAdi = "sym_depoid", dbType = DbType.Int32, idx = 1 });
            sayim.Fields.Add("EvrakNo", new FieldObject() { dbAdi = "sym_evrakno", dbType = DbType.Int32, idx = 3 });
            sayim.Fields.Add("Satir", new FieldObject() { dbAdi = "sym_satirno", dbType = DbType.Int32, idx = 4 });
            sayim.Fields.Add("StokId", new FieldObject() { dbAdi = "sym_stokid", dbType = DbType.Int32, idx = 5 });
            sayim.Fields.Add("BarkodId", new FieldObject() { dbAdi = "sym_barkodid", dbType = DbType.Int32, idx = 6 });
            sayim.Fields.Add("Miktar", new FieldObject() { dbAdi = "sym_miktar", dbType = DbType.Decimal, idx = 7 });
            sayim.Fields.Add("Gonderildi", new FieldObject() { dbAdi = "sym_gonderildi", dbType = DbType.Boolean, idx = 8 });
            sayim.Fields.Add("RecNo", new FieldObject() { dbAdi = "sym_recno", dbType = DbType.Int32, idx = 9 });

            sayim.Indexes.Add("PK", new IndexObject() { Fields = "sym_tarih,sym_depoid,sym_evrakno,sym_satirno", IndexType = IndexObject.Tip.PrimaryKey });
            sayim.Indexes.Add("STOKID", new IndexObject() { Fields = "sym_stokid", IndexType = IndexObject.Tip.Index });
            sayim.Indexes.Add("BARKODID", new IndexObject() { Fields = "sym_barkodid", IndexType = IndexObject.Tip.Index });
            sayim.Indexes.Add("BARKODMIKTAR", new IndexObject() { Fields = "sym_tarih,sym_depoid,sym_evrakno,sym_barkodid", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_SAYIM", sayim);

            TableObject kullanici = new TableObject();
            kullanici.TableName = "TBL_KULLANICI";
            kullanici.Fields.Add("Id", new FieldObject() { dbAdi = "rec_id", dbType = DbType.Int32, idx = 0 });
            kullanici.Fields.Add("Adi", new FieldObject() { dbAdi = "kul_kodu", dbType = DbType.String, idx = 1 });
            kullanici.Fields.Add("Kodu", new FieldObject() { dbAdi = "kul_adi", dbType = DbType.String, idx = 2 });
            kullanici.Fields.Add("Sifre", new FieldObject() { dbAdi = "kul_sifre", dbType = DbType.String, idx = 3 });
            kullanici.Indexes.Add("PK", new IndexObject() { Fields = "rec_id", IndexType = IndexObject.Tip.PrimaryKey });
            this.tables.Add("TBL_KULLANICI", kullanici);

            TableObject menu = new TableObject();
            menu.TableName = "TBL_MENU";
            menu.Fields.Add("MenuNo", new FieldObject() { dbAdi = "menu_no", dbType = DbType.Int32, idx = 0 });
            menu.Fields.Add("Kullanilabilir", new FieldObject() { dbAdi = "menu_kullanilir", dbType = DbType.Boolean, idx = 1 });
            menu.Fields.Add("MenuAdi", new FieldObject() { dbAdi = "menu_adi", dbType = DbType.String, idx = 2 });
            menu.Fields.Add("Sifreli", new FieldObject() { dbAdi = "menu_sifreli", dbType = DbType.Boolean, idx = 3 });
            menu.Indexes.Add("PK", new IndexObject() { Fields = "menu_no", IndexType = IndexObject.Tip.PrimaryKey });
            this.tables.Add("TBL_MENU", menu);


            TableObject doviz = new TableObject();
            doviz.TableName = "TBL_DOVIZ";
            doviz.Fields.Add("DovizNo", new FieldObject() { dbAdi = "doviz_no", dbType = DbType.Int32, idx = 0 });
            doviz.Fields.Add("Sembol", new FieldObject() { dbAdi = "doviz_sembol", dbType = DbType.String, idx = 1 });
            doviz.Fields.Add("Kur", new FieldObject() { dbAdi = "doviz_kur", dbType = DbType.Decimal, idx = 2 });
            doviz.Indexes.Add("PK", new IndexObject() { Fields = "doviz_no", IndexType = IndexObject.Tip.PrimaryKey });
            this.tables.Add("TBL_DOVIZ", doviz);

            TableObject cariBakiye = new TableObject();
            cariBakiye.TableName = "TBL_CARIBAKIYE";
            cariBakiye.Fields.Add("Id", new FieldObject() { dbAdi = "cari_id", dbType = DbType.Int32, idx = 0 });
            cariBakiye.Fields.Add("GenelBakiye", new FieldObject() { dbAdi = "cari_genel_bakiye", dbType = DbType.Decimal, idx = 1 });
            cariBakiye.Fields.Add("Bakiye1", new FieldObject() { dbAdi = "cari_srm_bakiye1", dbType = DbType.Decimal, idx = 2 });
            cariBakiye.Fields.Add("Bakiye2", new FieldObject() { dbAdi = "cari_srm_bakiye2", dbType = DbType.Decimal, idx = 3 });
            cariBakiye.Fields.Add("Bakiye3", new FieldObject() { dbAdi = "cari_srm_bakiye3", dbType = DbType.Decimal, idx = 4 });
            cariBakiye.Fields.Add("Bakiye4", new FieldObject() { dbAdi = "cari_srm_bakiye4", dbType = DbType.Decimal, idx = 5 });
            cariBakiye.Fields.Add("Bakiye5", new FieldObject() { dbAdi = "cari_srm_bakiye5", dbType = DbType.Decimal, idx = 6 });
            cariBakiye.Fields.Add("Bakiye6", new FieldObject() { dbAdi = "cari_srm_bakiye6", dbType = DbType.Decimal, idx = 7 });
            cariBakiye.Fields.Add("Bakiye7", new FieldObject() { dbAdi = "cari_srm_bakiye7", dbType = DbType.Decimal, idx = 8 });
            cariBakiye.Fields.Add("Bakiye8", new FieldObject() { dbAdi = "cari_srm_bakiye8", dbType = DbType.Decimal, idx = 9 });
            cariBakiye.Fields.Add("Bakiye9", new FieldObject() { dbAdi = "cari_srm_bakiye9", dbType = DbType.Decimal, idx = 10 });
            cariBakiye.Fields.Add("Bakiye10", new FieldObject() { dbAdi = "cari_srm_bakiye10", dbType = DbType.Decimal, idx = 11 });

            cariBakiye.Indexes.Add("PK", new IndexObject() { Fields = "cari_id", IndexType = IndexObject.Tip.PrimaryKey });
            this.tables.Add("TBL_CARIBAKIYE", cariBakiye);

            TableObject cari = new TableObject();
            cari.TableName = "TBL_CARI";
            cari.Fields.Add("Id", new FieldObject() { dbAdi = "cari_id", dbType = DbType.Int32, idx = 0 });
            cari.Fields.Add("Kodu", new FieldObject() { dbAdi = "cari_kod", dbType = DbType.String, idx = 1 });
            cari.Fields.Add("Unvan1", new FieldObject() { dbAdi = "cari_adi1", dbType = DbType.String, idx = 2 });
            cari.Fields.Add("Unvan2", new FieldObject() { dbAdi = "cari_adi2", dbType = DbType.String, idx = 3 });
            cari.Fields.Add("VergiDairesi", new FieldObject() { dbAdi = "cari_vergi_daire", dbType = DbType.String, idx = 4 });
            cari.Fields.Add("VergiNumarasi", new FieldObject() { dbAdi = "cari_vergi_no", dbType = DbType.String, idx = 5 });
            cari.Fields.Add("SaticiId", new FieldObject() { dbAdi = "cari_satici_id", dbType = DbType.Int32, idx = 6 });
            cari.Fields.Add("IskontoKodu", new FieldObject() { dbAdi = "cari_iskonto_kod", dbType = DbType.String, idx = 7 });
            cari.Fields.Add("FiyatNo", new FieldObject() { dbAdi = "cari_fiyat_no", dbType = DbType.Byte, idx = 8 });
            cari.Fields.Add("IskontoOrani", new FieldObject() { dbAdi = "cari_iskonto_orani", dbType = DbType.Byte, idx = 9 });
            cari.Fields.Add("Vade", new FieldObject() { dbAdi = "cari_vade", dbType = DbType.Int32, idx = 10 });

            cari.Indexes.Add("PK", new IndexObject() { Fields = "cari_id", IndexType = IndexObject.Tip.PrimaryKey });
            cari.Indexes.Add("KOD", new IndexObject() { Fields = "cari_kod", IndexType = IndexObject.Tip.Index });
            cari.Indexes.Add("UNVAN", new IndexObject() { Fields = "cari_adi1", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_CARI", cari);


            TableObject adres = new TableObject();
            adres.TableName = "TBL_ADRES";
            adres.Fields.Add("Id", new FieldObject() { dbAdi = "adres_id", dbType = DbType.Int32, idx = 0 });
            adres.Fields.Add("CariId", new FieldObject() { dbAdi = "adres_cari_id", dbType = DbType.Int32, idx = 1 });
            adres.Fields.Add("AdresNo", new FieldObject() { dbAdi = "adres_no", dbType = DbType.String, idx = 2 });
            adres.Fields.Add("Adres", new FieldObject() { dbAdi = "adres", dbType = DbType.String, idx = 3 });
            adres.Fields.Add("Il", new FieldObject() { dbAdi = "adres_il", dbType = DbType.String, idx = 4 });
            adres.Fields.Add("Ilce", new FieldObject() { dbAdi = "adres_ilce", dbType = DbType.String, idx = 5 });
            adres.Fields.Add("SaticiId", new FieldObject() { dbAdi = "adres_satici_id", dbType = DbType.Int32, idx = 6 });
            adres.Fields.Add("ZiyaretPeriyodu", new FieldObject() { dbAdi = "adres_periyod", dbType = DbType.Byte, idx = 7 });
            adres.Fields.Add("ZiyaretHaftasi", new FieldObject() { dbAdi = "adres_hafta", dbType = DbType.Byte, idx = 8 });
            adres.Fields.Add("OzelNot", new FieldObject() { dbAdi = "adres_not", dbType = DbType.String, idx = 9 });
            adres.Fields.Add("Gun1", new FieldObject() { dbAdi = "adres_gun1", dbType = DbType.Byte, idx = 10 });
            adres.Fields.Add("Gun2", new FieldObject() { dbAdi = "adres_gun2", dbType = DbType.Byte, idx = 11 });
            adres.Fields.Add("Gun3", new FieldObject() { dbAdi = "adres_gun3", dbType = DbType.Byte, idx = 12 });
            adres.Fields.Add("Gun4", new FieldObject() { dbAdi = "adres_gun4", dbType = DbType.Byte, idx = 13 });
            adres.Fields.Add("Gun5", new FieldObject() { dbAdi = "adres_gun5", dbType = DbType.Byte, idx = 14 });
            adres.Fields.Add("Gun6", new FieldObject() { dbAdi = "adres_gun6", dbType = DbType.Byte, idx = 15 });
            adres.Fields.Add("Gun7", new FieldObject() { dbAdi = "adres_gun7", dbType = DbType.Byte, idx = 16 });
            adres.Fields.Add("Tel1", new FieldObject() { dbAdi = "adres_tel1", dbType = DbType.String, idx = 17 });
            adres.Fields.Add("Tel2", new FieldObject() { dbAdi = "adres_tel2", dbType = DbType.String, idx = 18 });

            adres.Indexes.Add("PK", new IndexObject() { Fields = "adres_no,adres_cari_id", IndexType = IndexObject.Tip.PrimaryKey });
            this.tables.Add("TBL_ADRES", adres);


            TableObject matris = new TableObject();
            matris.TableName = "TBL_MATRIS";
            matris.Fields.Add("StokKodu", new FieldObject() { dbAdi = "matris_stok", dbType = DbType.String, idx = 0 });
            matris.Fields.Add("CariKodu", new FieldObject() { dbAdi = "matris_cari", dbType = DbType.String, idx = 1 });
            matris.Fields.Add("Vade", new FieldObject() { dbAdi = "matris_vade", dbType = DbType.Int32, idx = 2 });
            matris.Fields.Add("Oran1", new FieldObject() { dbAdi = "matris_isk1", dbType = DbType.Decimal, idx = 3 });
            matris.Fields.Add("Oran2", new FieldObject() { dbAdi = "matris_isk2", dbType = DbType.Decimal, idx = 4 });
            matris.Fields.Add("Oran3", new FieldObject() { dbAdi = "matris_isk3", dbType = DbType.Decimal, idx = 5 });
            matris.Fields.Add("Oran4", new FieldObject() { dbAdi = "matris_isk4", dbType = DbType.Decimal, idx = 6 });
            matris.Fields.Add("Oran5", new FieldObject() { dbAdi = "matris_isk5", dbType = DbType.Decimal, idx = 7 });
            matris.Fields.Add("Oran6", new FieldObject() { dbAdi = "matris_isk6", dbType = DbType.Decimal, idx = 8 });

            matris.Indexes.Add("PK", new IndexObject() { Fields = "matris_stok,matris_cari,matris_vade", IndexType = IndexObject.Tip.PrimaryKey });
            this.tables.Add("TBL_MATRIS", matris);

            TableObject evrak = new TableObject();
            evrak.TableName = "TBL_EVRAK";
            evrak.Fields.Add("Id", new FieldObject() { dbAdi = "evr_id", Identity = true, dbType = DbType.Int32, idx = 0 });
            evrak.Fields.Add("Tip", new FieldObject() { dbAdi = "evr_tip", dbType = DbType.Int32, idx = 1 });
            evrak.Fields.Add("Cins", new FieldObject() { dbAdi = "evr_cins", dbType = DbType.Int32, idx = 2 });
            evrak.Fields.Add("Seri", new FieldObject() { dbAdi = "evr_seri", dbType = DbType.String, idx = 3 });
            evrak.Fields.Add("Sira", new FieldObject() { dbAdi = "evr_sira", dbType = DbType.Int32, idx = 4 });
            evrak.Fields.Add("Satir", new FieldObject() { dbAdi = "evr_satir", dbType = DbType.Int32, idx = 5 });
            evrak.Fields.Add("BelgeNo", new FieldObject() { dbAdi = "evr_belgeno", dbType = DbType.String, idx = 6 });
            evrak.Fields.Add("Tarih", new FieldObject() { dbAdi = "evr_tarih", dbType = DbType.DateTime, idx = 7 });
            evrak.Fields.Add("SaticiKod", new FieldObject() { dbAdi = "evr_saticikod", dbType = DbType.String, idx = 8 });
            evrak.Fields.Add("CariKod", new FieldObject() { dbAdi = "evr_carikod", dbType = DbType.String, idx = 9 });
            evrak.Fields.Add("GirisDepo", new FieldObject() { dbAdi = "evr_giris_depo", dbType = DbType.Int32, idx = 10 });
            evrak.Fields.Add("CikisDepo", new FieldObject() { dbAdi = "evr_cikis_depo", dbType = DbType.Int32, idx = 11 });
            evrak.Fields.Add("SrmMerkezi", new FieldObject() { dbAdi = "evr_srm_merkezi", dbType = DbType.String, idx = 12 });
            evrak.Fields.Add("StokKod", new FieldObject() { dbAdi = "evr_stokkod", dbType = DbType.String, idx = 13 });
            evrak.Fields.Add("Fiyat", new FieldObject() { dbAdi = "evr_fiyat", dbType = DbType.Decimal, idx = 14 });
            evrak.Fields.Add("Miktar", new FieldObject() { dbAdi = "evr_miktar", dbType = DbType.Decimal, idx = 15 });
            evrak.Fields.Add("Tutar", new FieldObject() { dbAdi = "evr_tutar", dbType = DbType.Decimal, idx = 16 });
            evrak.Fields.Add("Isk1Tutar", new FieldObject() { dbAdi = "evr_isk1_tutar", dbType = DbType.Decimal, idx = 17 });
            evrak.Fields.Add("Isk2Tutar", new FieldObject() { dbAdi = "evr_isk2_tutar", dbType = DbType.Decimal, idx = 18 });
            evrak.Fields.Add("Isk3Tutar", new FieldObject() { dbAdi = "evr_isk3_tutar", dbType = DbType.Decimal, idx = 19 });
            evrak.Fields.Add("Isk4Tutar", new FieldObject() { dbAdi = "evr_isk4_tutar", dbType = DbType.Decimal, idx = 20 });
            evrak.Fields.Add("Isk5Tutar", new FieldObject() { dbAdi = "evr_isk5_tutar", dbType = DbType.Decimal, idx = 21 });
            evrak.Fields.Add("Isk6Tutar", new FieldObject() { dbAdi = "evr_isk6_tutar", dbType = DbType.Decimal, idx = 22 });
            evrak.Fields.Add("Isk1Oran", new FieldObject() { dbAdi = "evr_isk1_oran", dbType = DbType.Decimal, idx = 23 });
            evrak.Fields.Add("Isk2Oran", new FieldObject() { dbAdi = "evr_isk2_oran", dbType = DbType.Decimal, idx = 24 });
            evrak.Fields.Add("Isk3Oran", new FieldObject() { dbAdi = "evr_isk3_oran", dbType = DbType.Decimal, idx = 25 });
            evrak.Fields.Add("Isk4Oran", new FieldObject() { dbAdi = "evr_isk4_oran", dbType = DbType.Decimal, idx = 26 });
            evrak.Fields.Add("Isk5Oran", new FieldObject() { dbAdi = "evr_isk5_oran", dbType = DbType.Decimal, idx = 27 });
            evrak.Fields.Add("Isk6Oran", new FieldObject() { dbAdi = "evr_isk6_oran", dbType = DbType.Decimal, idx = 28 });
            evrak.Fields.Add("VergiId ", new FieldObject() { dbAdi = "evr_vergi_id", dbType = DbType.Decimal, idx = 29 });
            evrak.Fields.Add("VergiTutari", new FieldObject() { dbAdi = "evr_vergi_tutar", dbType = DbType.Decimal, idx = 30 });
            evrak.Fields.Add("Gonderildi", new FieldObject() { dbAdi = "evr_gonderildi", dbType = DbType.Int32, idx = 31 });
            evrak.Fields.Add("Vade", new FieldObject() { dbAdi = "evr_vade", dbType = DbType.Decimal, idx = 32 });
            evrak.Fields.Add("Aciklama", new FieldObject() { dbAdi = "evr_aciklama", dbType = DbType.String, idx = 33, dbLenght = 100 });

            evrak.Indexes.Add("PK", new IndexObject() { Fields = "evr_cins,evr_seri,evr_sira,evr_satir", IndexType = IndexObject.Tip.PrimaryKey });
            evrak.Indexes.Add("STOKKOD", new IndexObject() { Fields = "evr_stokkod", IndexType = IndexObject.Tip.Index });
            evrak.Indexes.Add("CARIKOD", new IndexObject() { Fields = "evr_carikod", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_EVRAK", evrak);

            TableObject ths = new TableObject();
            ths.TableName = "TBL_TAHSILAT";
            ths.Fields.Add("Id", new FieldObject() { dbAdi = "ths_id", Identity = true, dbType = DbType.Int32, idx = 0 });
            ths.Fields.Add("Tip", new FieldObject() { dbAdi = "ths_tip", dbType = DbType.Int32, idx = 1 });
            ths.Fields.Add("Seri", new FieldObject() { dbAdi = "ths_seri", dbType = DbType.String, idx = 2 });
            ths.Fields.Add("Sira", new FieldObject() { dbAdi = "ths_sira", dbType = DbType.Int32, idx = 3 });
            ths.Fields.Add("Satir", new FieldObject() { dbAdi = "ths_satir", dbType = DbType.Int32, idx = 4 });
            ths.Fields.Add("BelgeNo", new FieldObject() { dbAdi = "ths_belgeno", dbType = DbType.String, idx = 5 });
            ths.Fields.Add("Tarih", new FieldObject() { dbAdi = "ths_tarih", dbType = DbType.DateTime, idx = 6 });
            ths.Fields.Add("VadeTarihi", new FieldObject() { dbAdi = "ths_vade_tarih", dbType = DbType.DateTime, idx = 7 });
            ths.Fields.Add("SaticiKod", new FieldObject() { dbAdi = "ths_saticikod", dbType = DbType.String, idx = 8 });
            ths.Fields.Add("CariKod", new FieldObject() { dbAdi = "ths_carikod", dbType = DbType.String, idx = 9 });
            ths.Fields.Add("SrmMerkezi", new FieldObject() { dbAdi = "ths_srm_merkezi", dbType = DbType.String, idx = 10 });
            ths.Fields.Add("ReferansNo", new FieldObject() { dbAdi = "ths_referans_no", dbType = DbType.String, idx = 11 });
            ths.Fields.Add("CekSenetNo", new FieldObject() { dbAdi = "ths_ceksenet_no", dbType = DbType.String, idx = 11 });
            ths.Fields.Add("Meblag", new FieldObject() { dbAdi = "ths_meblag", dbType = DbType.Decimal, idx = 12 });
            ths.Fields.Add("Aciklama", new FieldObject() { dbAdi = "ths_aciklama", dbType = DbType.String, idx = 13, dbLenght = 100 });
            ths.Fields.Add("Gonderildi", new FieldObject() { dbAdi = "ths_gonderildi", dbType = DbType.Int32, idx = 14 });

            ths.Indexes.Add("PK", new IndexObject() { Fields = "ths_seri,ths_sira,ths_satir", IndexType = IndexObject.Tip.PrimaryKey });
            ths.Indexes.Add("CARIKOD", new IndexObject() { Fields = "ths_carikod", IndexType = IndexObject.Tip.Index });
            this.tables.Add("TBL_TAHSILAT", ths);

        }

        public void CreateOrUpdateDb()
        {
            string cnnStr = "Data Source=" + Path.Combine(Methods.StartupPath(), "DB.sdf");

            if (!File.Exists(Path.Combine(Methods.StartupPath(), "DB.sdf")))
            {
                SqlCeClient.Get.CreateDb(cnnStr);
                using (DbBarkod tbl = new DbBarkod())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbStok tbl = new DbStok())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbDepo tbl = new DbDepo())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbEnvanter tbl = new DbEnvanter())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbSayim tbl = new DbSayim())
                    SqlCeClient.Get.CreateTable(tbl);

                using (Kullanici tbl = new Kullanici())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbMenu tbl = new DbMenu())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbCari tbl = new DbCari())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbCariAdres tbl = new DbCariAdres())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbMatris tbl = new DbMatris())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbEvrak tbl = new DbEvrak())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbSrmMerkezi tbl = new DbSrmMerkezi())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbDoviz tbl = new DbDoviz())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbCariBakiye tbl = new DbCariBakiye())
                    SqlCeClient.Get.CreateTable(tbl);

                using (DbTahsilat tbl = new DbTahsilat())
                    SqlCeClient.Get.CreateTable(tbl);
            }
            else
            {
                using (DbBarkod tbl = new DbBarkod())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbStok tbl = new DbStok())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbDepo tbl = new DbDepo())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbEnvanter tbl = new DbEnvanter())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbSayim tbl = new DbSayim())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (Kullanici tbl = new Kullanici())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbMenu tbl = new DbMenu())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbCari tbl = new DbCari())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbCariAdres tbl = new DbCariAdres())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbMatris tbl = new DbMatris())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbEvrak tbl = new DbEvrak())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbSrmMerkezi tbl = new DbSrmMerkezi())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbDoviz tbl = new DbDoviz())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbCariBakiye tbl = new DbCariBakiye())
                    SqlCeClient.Get.ValidateTable(tbl);

                using (DbTahsilat tbl = new DbTahsilat())
                    SqlCeClient.Get.ValidateTable(tbl);
            }
        }
    }

    public class TableObject
    {
        public string TableName { get; set; }
        Dictionary<string, FieldObject> fields = new Dictionary<string, FieldObject>();
        Dictionary<string, IndexObject> indexes = new Dictionary<string, IndexObject>();

        public Dictionary<string, FieldObject> Fields { get { return fields; } }
        public Dictionary<string, IndexObject> Indexes { get { return indexes; } }
    }

    public struct FieldObject
    {
        public byte idx { get; set; }
        public string dbAdi { get; set; }
        public DbType dbType { get; set; }
        public int dbLenght { get; set; }
        public byte Precision { get; set; }
        public bool Identity { get; set; }
        public bool AllowsNulls { get; set; }
        public bool RequireUniqueValue { get; set; }
    }

    public struct IndexObject
    {
        public enum Tip
        {
            Index, PrimaryKey
        }
        public string Fields { get; set; }
        public Tip IndexType { get; set; }
    }

}
